﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System;
using System.Web.Security;
using System.ComponentModel;
using Code.Models;
using Code.BLL;
using Code.Commen;

namespace RuiJing.Web.Controllers
{
    [HandleError]
    public class ControllerBase : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ViewData["Route_L"] = RouteData.Values["l"];
            ViewData["Route_A"] = RouteData.Values["a"];
            ViewData["Route_B"] = RouteData.Values["b"];
            ViewData["Route_C"] = RouteData.Values["c"];
            ViewData["Route_D"] = RouteData.Values["d"];
            RouteData.Values.Remove("l");
            RouteData.Values.Remove("a");
            RouteData.Values.Remove("b");
            RouteData.Values.Remove("c");
            RouteData.Values.Remove("d");

            var lstr = ViewData["Route_L"] as string;
            Language l;
            if (lstr != null)
            {
                var c = new EnumConverter(typeof(Language));
                l = (Language)c.ConvertFromString(lstr);
            }
            else
                l = Language.En;
            ViewData["Title"] = CommenManage.Options[(OptionKey)new EnumConverter(typeof(OptionKey)).ConvertFromString("Site_Info_CompanyName_" + l)].Value;
            ViewData["KeyWord"] = CommenManage.Options[(OptionKey)new EnumConverter(typeof(OptionKey)).ConvertFromString("Site_Info_KeyWord_" + l)].Value;
        }

        protected override void OnException(ExceptionContext filterContext)
        {
            var log = Log.GetLog<ControllerBase>();

            log.Error(filterContext.Exception);

            filterContext.Result = View("Error");
            filterContext.ExceptionHandled = true;
        }
    }
}
